package com.neuedu.studentmanage.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neuedu.studentmanage.entity.Homework;
import com.neuedu.studentmanage.entity.Pager;
import com.neuedu.studentmanage.service.HomeworkService;

@Controller
public class HomeworkController {

	@Autowired
	private HomeworkService homeworkService;

	@GetMapping("homework/index")
	public String goTo() {
		return "student/homework/homework";
	}
	
	@PostMapping("homework/list")
	@ResponseBody
	public Pager<Homework> findList(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "rows", defaultValue = "10") Integer rows) {
		Pager<Homework> pager = new Pager<>(page, rows);
		List<Homework> outRequests = homeworkService.findListByPager(pager);
		Integer total = homeworkService.findTotalByPager(pager);

		pager.setRows(outRequests);
		pager.setTotal(total);

		return pager;
	}
}
